package com.zeta.eduservice.controller.Front;

import java.util.List;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zeta.commonutils.R;
import com.zeta.eduservice.entity.EduTeacher;
import com.zeta.eduservice.entity.question.EduCourse;
import com.zeta.eduservice.service.EduCourseService;
import com.zeta.eduservice.service.EduTeacherService;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@CrossOrigin
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

	@Autowired
	private EduTeacherService teacherService;
	

	@Autowired
	private EduCourseService courseService;
	@ApiOperation(value = "分页讲师列表")
	@GetMapping(value = "{page}/{limit}")
	public R pageList(
	    @ApiParam(name = "page", value = "当前页码", required = true)
	    @PathVariable Long page,

	    @ApiParam(name = "limit", value = "每页记录数", required = true)
	    @PathVariable Long limit){

	    Page<EduTeacher> pageParam = new Page<EduTeacher>(page, limit);

	    Map<String, Object> map = teacherService.pageListWeb(pageParam);

	    return  R.ok().data(map);
	}
	 @GetMapping("{id}")
	    public R getTeacherFrontInfo(@PathVariable String id) {
	        //1 根据讲师id查询讲师基本信息
	        EduTeacher eduTeacher = teacherService.getById(id);
	        //2 根据讲师id查询所讲课程
	        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
	        wrapper.eq("teacher_id",id);
	        List<EduCourse> courseList = courseService.list(wrapper);
	        return R.ok().data("teacher",eduTeacher).data("courseList",courseList);
	    }

}
